using System;
using System.Runtime.InteropServices;

namespace NovaCore.Interop {
	public static class SmsEncoding {
		public const int MAX_PDU_LENGTH = 200;
		public const int MAX_SPECIAL_CHAR_LENGTH = 10;
		public const int MAX_ADDRESS_CHAR_LENGTH = 50;
		public const int MAX_CALLBACK_CHAR_LENGTH = 20;
		public const int MAX_MESSAGE_CHAR_LENGTH = 160;
		public const int MAX_SUBJECT_CHAR_LENGTH = 160;

		[DllImport(NvtlConstants.LIB_SMSENCODE)]
		public static extern NvtlErrorCode SmsDecodeMessage(out SMS_MSG_DATA sms_msg, byte[] enc_msg_buf, short msg_buf_len, byte isSubmitType);

		[DllImport(NvtlConstants.LIB_SMSENCODE)]
		public static extern NvtlErrorCode SmsEncodeMessage(ref SMS_MSG_DATA sms_msg, byte[] msg_buf, ref short msg_buf_len);

		[DllImport(NvtlConstants.LIB_SMSENCODE)]
		public static extern NvtlErrorCode SmsGetMessageMetrics(string msg, out short numMsgs, out short curMsgLen, out short maxMsgLen, out EncodingType bestEncoding);

		[DllImport(NvtlConstants.LIB_SMSENCODE)]
		public static extern NvtlErrorCode SmsSetMessageFormat(EMsgFormat sms_format);
	}

	[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
	public struct SMS_DEVICE_PROP {
		public int nMaxMsgLength;
		public int nMaxMsgLengthUnicode;
		public int nMaxMsgLengthLatin1;
		public int nMaxMultiMsgLength;
		public int nMaxMultiMsgLengthUnicode;
		public int nMaxMultiMsgLengthLatin1;
		public int nMaxMultiMessages;
		public int nMaxMOCount;
		public char byteNULL;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=SmsEncoding.MAX_SPECIAL_CHAR_LENGTH+1)]
		public string sSpecialChars;
	}

	[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
	public struct SMS_MSG_DATA {
		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=SmsEncoding.MAX_ADDRESS_CHAR_LENGTH+1)]
		public string sAddress;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=SmsEncoding.MAX_CALLBACK_CHAR_LENGTH+1)]
		public string sCallback;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=SmsEncoding.MAX_MESSAGE_CHAR_LENGTH+1)]
		public string sMessage;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=SmsEncoding.MAX_ADDRESS_CHAR_LENGTH+1)]
		public string sSmscAddress;

		[MarshalAs(UnmanagedType.ByValTStr, SizeConst=SmsEncoding.MAX_SUBJECT_CHAR_LENGTH+1)]
		public string sSubject;

		public byte msgLength;
		public byte pduType;
		public short msgRef;
		public byte msgSequence;
		public byte msgTotal;
		public EMsgPriority nPriority;
		public tm tTime;
		public EncodingType encoding;
		public byte bReceipt;
		public int dwDataMask;
		public tm tValidity;
		public byte nValidityType;
		public byte bRelativeValidityFlag;
		public byte isDeliveryAck;
	}
	

	public enum EMsgPriority {
		msgEMERGENCY = 0,
		msgURGENT,
		msgNORMAL,
		msgINTERACTIVE
	}

	public enum EMsgFormat {
		SMS_TYPE_PDU = 0,
		SMS_TYPE_WMS = 1,
		SMS_TYPE_IS637 = 2
	}

	public enum EMsgValidityType {
		msgValidityUNKNOWN,
		msgValidityENHANCED,
		msgValidityRELATIVE,
		msgValidityABSOLUTE
	}

	public enum EMsgRelativeValidityType {
		msgRelValidity_TIMELIMIT = 0,
		msgRelValidity_INDEFINITE = 245,
		msgRelValidity_IMMEDIATE = 246,
		msgRelValidity_MOBILEACTIVE = 247,
		msgRelValidity_REG_AREA = 248
	}

	public enum EMsgState {
		msgUNREAD = 3,
		msgREAD,
		msgREPLY,
		msgFORWARD,
		msgSENDING,
		msgFAILED,
		msgSENT,
		msgDELIVERED
	}

	public enum EncodingType {
		En_ASCII_7Bit,
		En_UNICODE,
		En_LATIN_1,
		En_GSM_7Bit,
		En_INVALID = 99,
	}
}